package com.liziba.trend.config;

import org.springframework.boot.web.context.WebServerInitializedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;

/**
 * @program: trend
 * @description: 获取当前服务的端口号
 * @author: liziba
 * @date: 2021-02-03 10:50
 */
@Configuration
public class IpConfiguration implements ApplicationListener<WebServerInitializedEvent> {

    /**
     * 端口号
     */
    private int serverPort;

    public int getServerPort() {
        return serverPort;
    }

    /**
     * 获取当前服务的端口号
     * @param event
     */
    @Override
    public void onApplicationEvent(WebServerInitializedEvent event) {
        this.serverPort = event.getWebServer().getPort();
    }


}
